package com.hk.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hk.core.roleResult.PageRoleResult;
import com.hk.domain.SysNotice;
import com.hk.mapper.SysNoticeMapper;
import com.hk.service.SysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

@Service
public class SysNoticeServiceImpl implements SysNoticeService {
    @Autowired
    private SysNoticeMapper sysNoticeMapper;
    @Override
    public PageRoleResult listByStatus(Integer status) {
        Page<SysNotice> sysNoticePage = new Page<>(0, 20);
        LambdaQueryWrapper<SysNotice> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysNotice::getStatus, status);
        wrapper.orderByDesc(SysNotice::getCreateTime);
        Page<SysNotice> page = sysNoticeMapper.selectPage(sysNoticePage, wrapper);
        PageRoleResult pageRoleResult = new PageRoleResult();
        pageRoleResult.setRows(page.getRecords());
        pageRoleResult.setTotal((int) page.getTotal());
        pageRoleResult.setMsg("查询成功");
        pageRoleResult.setCode(200);
        return pageRoleResult;
    }
//通过id查询
    @Override
    public SysNotice selcetById(Integer noticeId) {
        LambdaQueryWrapper<SysNotice> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysNotice::getNoticeId,noticeId);
        return sysNoticeMapper.selectOne(wrapper);
    }

}
